package vcp.server.requesthandler;

import ocsf.server.ConnectionToClient;
import vcp.client.request.FillComplaintRequest;
import vcp.client.request.response.ResponseRequest;
import vcp.entity.Complaint;
import vcp.server.DAO.ComplaintDAO;
import vcp.server.interfaces.IServer;
import vcp.server.utility.Constants.TableNames;
/**
 * 
 * @author VCP team
 *<p>
 *class handles filling complaint from client
 *</p>
 */
public class FillComplaintRequestHandler extends RequestHandler <FillComplaintRequest>
{
	/**
	 * class constructor
	 * @param server
	 */
	public FillComplaintRequestHandler ( IServer server )
	{
		super(server);
	}

	@Override
	public void execute ( FillComplaintRequest request, ConnectionToClient client )
	{
		ComplaintDAO complaintDAO = new ComplaintDAO();

		Complaint newComplaint = request.getForm().getComplaint();
		newComplaint.setID(this.server.getGeneratedID(TableNames.COMPLAINT));
		newComplaint.setCustomerID(request.getCustomer().getCustomerID());

		complaintDAO.save(request.getForm().getComplaint());

		newComplaint.setCustomerOfComplaint(request.getCustomer());
		this.sendResponseRefresh(newComplaint, client);

		this.sendResponse(new ResponseRequest(request.getRequestID(), request.getForm().getComplaint()), client);
	}

}
